from common.common_operation import CommonOperation
from common.read_xmind import ReadXmind


class SelectRadioCheckOperation(CommonOperation):

    def generate_case(self, model_data, data_step, need_data, case_data):
        """
        生成用例
        :param model_data: 模块数据
        :param data_step: 对应的步骤
        :param need_data: 需求
        :return:
        """
        # TODO 是否必填
        self.required(need_data, model_data, data_step, '', case_data)
        # TODO 无论是否单选还是多选，全部选择一个值
        for i in need_data['值']:
            case_title = "{},{}:{}，{}".format(model_data['用例标题'], data_step, i, model_data['结果']['成功'])
            self.step_common(model_data, data_step, i, '成功', case_data, case_title)
        # TODO 不传“选项”字段的时候，默认为单选生成相关用例;传了“选项”字段，处理多选生成用例
        try:
            if need_data['选择类型']['value'] == '多选':
                case_title = "{},选择所有{}，{}".format(model_data['用例标题'], data_step[2:], model_data['结果']['成功'])
                self.step_common(model_data, data_step, need_data['值'], '成功', case_data, case_title)
        except:
            pass

    def case(self):
        return self.operation_type('选择框', self.generate_case)


def result():
    return SelectRadioCheckOperation().case()


if __name__ == '__main__':
    import json

    ReadXmind(path=r'C:\Users\admin\Desktop\NAVS.xmind', sheet='选择框').processed_data()
    test = result()
    print(json.dumps(test, ensure_ascii=False))
